<h3>Load vouchers</h3>

<? if (!$this->hideForm): ?>

<form class="form-horizontal" method="POST">

  <fieldset>

    <legend>Add new vouchers to the database</legend>

    <div class="control-group">

      <label class="control-label" for="separator">Separator</label>

      <div class="controls">

		<input type="text" id="separator" name="separator" value=";">

      </div>

    </div>

	<? for ($i=1; $i <= 7; $i++): ?>

    <div class="control-group">

      <label class="control-label" for="vouchers">Col <?= $i ?></label>

      <div class="controls">

	    <select name="col_<?= $i ?>">
			
		<option value="_">(Skip)</option>

		<option value="xtra">(Ignore)</option>
			
		  <option <?= ($i == 1)?'selected':'' ?> value="voucher">Bin</option>

		  <option <?= ($i == 2)?'selected':'' ?> value="cvv">CVV</option>

		  <option <?= ($i == 3)?'selected':'' ?> value="exp_date">Expiration Date</option>

		  <option <?= ($i == 4)?'selected':'' ?> value="name">Name</option>

		  <option <?= ($i == 5)?'selected':'' ?> value="city">City</option>

		  <option <?= ($i == 6)?'selected':'' ?> value="address">Address</option>

		  <option <?= ($i == 7)?'selected':'' ?> value="zip">Zip</option>

		</select>

      </div>
      
       
    </div>

	<? endfor; ?>
    
        <div class="control-group">
      <label class="control-label" for="vouchers">Reseller</label>
      <div class="controls">
        <select name="reseller">
            <option value=''>    Select Reseller    </option>
            <?php foreach($this->resellers as $reseller_key => $_reseller):?>
            <option value='<?php echo $reseller_key;?>'><?php echo $_reseller;?></option>
            <?php endforeach;?>
        </select>
     </div>
     </div>
    
    
	<div class="control-group">

      <label class="control-label" for="price">Price</label>

      <div class="controls">

	    <input type="text" id="price" name="price" />

      </div>

    </div>

    <div class="control-group">

      <label class="control-label" for="vouchers">Vouchers</label>

      <div class="controls">

		<textarea name="vouchers" rows=5 style="Width:90%"></textarea><br>

		<span style="color:#AAA; font-size:11px;">

  		  <strong>Format:</strong> voucher number ; cvv; yyyy-mm-dd ; name; city; address; zip

		</span> 

      </div>

    </div>

    <div class="control-group">

      <div class="controls">

        <button type="submit" class="btn btn-success">Load vouchers</button>
		
				<input type='button' class="btn btn-success" onclick='addColumn(); return false;' value="Add Column" />

      </div>

    </div>

  </fieldset>

</form>

<? endif; ?>

<? if (!$this->hideResult): ?>

<table class="table table-striped table-condensed table-hover">

  <tr>

	<th>Bin</th>

	<th>CVV</th>

	<th>Expires</th>

	<th>Name</th>

	<th>City</th>

	<th>Address</th>

	<th>Zip</th>

	<th>Price</th>

	<th style="width:30px;">Info</th>

  </tr>

  <? foreach ($this->vouchers as $voucher): ?>

    <tr>

      <td><?= $voucher['voucher'] ?></td>

      <td><?= $voucher['cvv'] ?></td>

      <td><?= $voucher['exp_date'] ?></td>

      <td><?= $voucher['name'] ?></td>

      <td><?= $voucher['city'] ?></td>

      <td><?= $voucher['address'] ?></td>

      <td><?= $voucher['zip'] ?></td>

      <td><?= $voucher['price'] ?></td>

      <td>

        <? if ($voucher['exists']): ?>

		  <span class="label">Already exists</span>

        <? else: ?>

		  <span class="label label-success">New</span>

        <? endif; ?>

	  </td>

    </tr>

  <? endforeach; ?>

</table>

<form class="form-horizontal" method="POST">

	<input type="hidden" value="<?= base64_encode(serialize($this->vouchers)) ?>" name="serVouchers">
        <input type="hidden" value="<?php echo $this->resellerId;?>" name="resellerid">
        
    <button type="submit" class="btn btn-success">Load vouchers</button>

</form>

<? endif; ?>


<script type='text/javascript'>
	var initialIndex = 7;
	function addColumn() {
		var obj = $("[name='col_" + initialIndex + "']").parent().parent();
		initialIndex++;
		obj.after("\
		<div class=\"control-group\" style=\"display:none;\">\
      <label class=\"control-label\" for=\"\">Col " + initialIndex + "</label>\
      <div class=\"controls\">\
	    <select name=\"col_"+initialIndex+"\">\
			<option value=\"_\">(Skip)</option>\
			<option value=\"xtra\">(Ignore)</option>\
		  <option value=\"voucher\">Bin</option>\
		  <option value=\"cvv\">CVV</option>\
		  <option value=\"exp_date\">Expiration Date</option>\
		  <option value=\"name\">Name</option>\
		  <option value=\"city\">City</option>\
		  <option value=\"address\">Address</option>\
		  <option value=\"zip\">Zip</option>\
			</select>\
      </div>\
		</div>\
		");

		obj = obj.next();
		obj.slideDown();
	}

</script>
